package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @className: PropertiesController
 * @author: 芃
 * @description: 测试读取配置文件
 * @date: 2024/12/23 15:27
 */
@RestController
@RequestMapping("/properties")
public class PropertiesController {

    @Value("${demo.key1}")
    private String key;

    @Value("${demo.key2}")
    private String key2;

    @Value("${demo.key3}")
    private String key3;

    @RequestMapping("/readKey")
    public String readKey(){
        return "读取到的配置项：" + key;
    }

    @PostConstruct//在项目启动之前执行
    public void init(){
        System.out.println("读取到的配置项：" + key + " " + key2 + " " + key3);
    }
}
